package com.balance.anole.client.retail.vo;

import java.math.BigDecimal;

import com.balance.anole.business.to.ProductItemTO;
import com.balance.anole.business.to.ProductPriceTO;
import com.balance.anole.business.to.ShopReceiptPdtItemTO;
import com.balance.anole.common.to.CodeLookTO;
import com.balance.anole.utils.Constants;


public class RetailVO extends ShopReceiptPdtItemTO{

	/**
	 *
	 */
	private static final long serialVersionUID = 8847118898606504134L;


	public boolean isRejected() {
		if( this.getNumOfPdtItem().intValue() < 0){
			return true;
		}else{
			return false;
		}
	}

	public BigDecimal getAmountAfterDiscount() {
		ProductPriceTO ppt = this.getPdtItem().getProductTO().getPriceByType(new CodeLookTO(Constants.CODE_TYPE_PRODUCT_PRICE_TYPE, "S"));
		BigDecimal price = ppt == null ? BigDecimal.ZERO : ppt.getPrice();
		BigDecimal discount = this.getPdtItem().getProductTO().getDiscRate();
		BigDecimal num = this.getNumOfPdtItem();

		BigDecimal discountPrice = price.multiply(discount);

		return discountPrice.multiply(num);
	}

	public BigDecimal getAmountBeforeDiscount() {
		ProductPriceTO ppt = this.getPdtItem().getProductTO().getPriceByType(new CodeLookTO(Constants.CODE_TYPE_PRODUCT_PRICE_TYPE, "S"));
		BigDecimal price = ppt == null ? BigDecimal.ZERO : ppt.getPrice();
		BigDecimal num = this.getNumOfPdtItem();
		return price.multiply(num);
	}

	public BigDecimal getDiscount(){
		ProductPriceTO ppt = this.getPdtItem().getProductTO().getPriceByType(new CodeLookTO(Constants.CODE_TYPE_PRODUCT_PRICE_TYPE, "S"));
		BigDecimal price = ppt == null ? BigDecimal.ZERO : ppt.getPrice();
		BigDecimal discount = new BigDecimal("1").subtract(this.getPdtItem().getProductTO().getDiscRate());
		BigDecimal num = this.getNumOfPdtItem();

		BigDecimal discountPrice = price.multiply(discount);

		return discountPrice.multiply(num);
	}

	public RetailVO(){

	}

	public RetailVO(ShopReceiptPdtItemTO shopReceiptPdtItemTO){
		this.setNumOfPdtItem(shopReceiptPdtItemTO.getNumOfPdtItem());
		this.setPdtItem(shopReceiptPdtItemTO.getPdtItem());
		this.setReceipt(shopReceiptPdtItemTO.getReceipt());
		this.setCreateBy(shopReceiptPdtItemTO.getCreateBy());
		this.setCreateDt(shopReceiptPdtItemTO.getUpdateDt());
		this.setUpdateBy(shopReceiptPdtItemTO.getUpdateBy());
		this.setUpdateDt(shopReceiptPdtItemTO.getUpdateDt());
	}

	public RetailVO(ProductItemTO productItemTO){
		this(productItemTO,1);
	}

	public RetailVO(ProductItemTO productItemTO, int num){
		this.setPdtItem(productItemTO);
		this.setNumOfPdtItem(new BigDecimal(num));
	}
}
